% binary vector transform to a decimal number
% determine whether the binary is a negative number
function dec = binary_to_dec(binary_vector)

symbol = binary_vector(1);
len = length(binary_vector);
% positive number
if  symbol == 0
    dec = bin2dec(num2str(binary_vector));
else
    % if symbal is negative
    % complement to radix-minus-one complement
    radix_dec = bin2dec(num2str(binary_vector)) - bin2dec('1'); 
    redix_complement_bin = dec_to_binary(radix_dec, 6);
    bin = ~redix_complement_bin;
    dec = -bin2dec(num2str(bin(1,2:len)));
end

end